package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.product.BaseCategoryFeignClient;
import com.atguigu.gmall.product.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private BaseCategoryFeignClient baseCategoryFeignClient ;

    @GetMapping(value = { "/" , "/index.html"})
    public String index(Model model) {     // 方法的返回值表示的就是要跳转的页面的名称

        //通过openFeign调用service-product微服务中查询三级分类的接口
        Result<List<CategoryVo>> result = baseCategoryFeignClient.findAllCategory();
        List<CategoryVo> categoryVoList = result.getData();

        // 把三级分类的数据存储到Model数据模型中
        model.addAttribute("list" , categoryVoList) ;

        // 进行页面跳转
        return "index/index" ;          // templates/index/index.html
    }

}
